'use strict';
const BaseController = require('./base');
const serviceName = 'idleFavorite';

class IdleFavoriteController extends BaseController {
  constructor(ctx) {
    super(ctx, serviceName);
  }

  async toggle() {
    const { ctx } = this;
    const { item_id, user_id } = ctx.request.body;

    if (!item_id) {
      ctx.throw(400, '物资/设备ID不能为空');
    }

    const result = await ctx.service[this.serviceName].toggle(user_id, item_id);
    ctx.success(result);
  }

  async myFavorites() {
    const { ctx } = this;
    const { user_id }  = ctx.query
    const result = await ctx.service[this.serviceName].getMyFavorites(user_id, ctx.query);
    ctx.success(result);
  }

  async check() {
    const { ctx } = this;
    const { item_id, user_id } = ctx.query;

    if (!item_id) {
      ctx.throw(400, '物资/设备ID不能为空');
    }

    const result = await ctx.service[this.serviceName].check(user_id, item_id);
    ctx.success(result);
  }
}

module.exports = IdleFavoriteController;
